{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.common import PayReceive, Currency\n",
    "from gs_quant.instrument import IRSwaption\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from gs_quant.session import Environment, GsSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'gs_quant_analytics_internal'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\kwokdo\\AppData\\Local\\Temp/ipykernel_1004/1815385159.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdatetime\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mdt\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mgs_quant_analytics_internal\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcomponents\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvanilla_contour_pricer\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mGenericPayoffContourPricer\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mVanillaPayoffContourPricer\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     12\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mgs_quant_analytics_internal\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcomponents\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexotic_contour_pricer\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mExoticPayoffContourPricer\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     13\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mgs_quant_analytics_internal\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcomponents\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxasset\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpayoff_contour_pricer\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mPayoffContourPricerParams\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'gs_quant_analytics_internal'"
     ]
    }
   ],
   "source": [
    "from gs_quant.session import GsSession\n",
    "from gs_quant.markets import PricingContext,LiveMarket\n",
    "from gs_quant.datetime import date_range\n",
    "from gs_quant.markets import PricingContext,LiveMarket\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from gs_quant.risk.results import PricingFuture, PortfolioRiskResult\n",
    "from gs_quant.target.common import MapParameter\n",
    "from gs_quant_internal.boltweb import valuation\n",
    "import datetime as dt\n",
    "\n",
    "from gs_quant_analytics_internal.components.fx.vanilla_contour_pricer import GenericPayoffContourPricer,VanillaPayoffContourPricer\n",
    "from gs_quant_analytics_internal.components.fx.exotic_contour_pricer import ExoticPayoffContourPricer\n",
    "from gs_quant_analytics_internal.components.xasset.payoff_contour_pricer import PayoffContourPricerParams\n",
    "from gs_quant_analytics_internal.components.xasset.payoff_contours import PayoffContours\n",
    "from gs_quant.session import GsSession,Environment\n",
    "from gs_quant.common import AssetClass\n",
    "from gs_quant_analytics_internal.xasset.utils import builder_to_priceable_asset, quick_entry_to_portfolio\n",
    "GsSession.use()\n",
    "live_pricing = PricingContext(market=LiveMarket('LDN'),market_data_location='LDN',)\n",
    "opt = tdapi.FXOptionBuilder(\n",
    "    over=\"JPY\",\n",
    "    under='USD',\n",
    "    expiry='2021-12-29',\n",
    "    size='5M',\n",
    "    strike='113.465',\n",
    "    hedgetype='spot')\n",
    "with live_pricing:\n",
    "    spot=opt.calc(valuation('FXSpot'))\n",
    "    fwd=opt.calc(valuation('FXFwd'))\n",
    "    pricepct = opt.calc(valuation('PricePct'))\n",
    "    volatility = opt.calc(valuation('FXVol'))\n",
    "    winghedge = opt.calc(valuation('FXCalcHedge'))\n",
    "\n",
    "opt.valuation_overrides = {\n",
    "        'FXSpot':spot.result(), \n",
    "        'FXFwd':fwd.result(),\n",
    "        'FXVol':volatility.result(),\n",
    "        'PricePct':pricepct.result()}\n",
    "opt.hedge = winghedge.result()\n",
    "with live_pricing:\n",
    "    opt.resolve()\n",
    "    new_portfolio = Portfolio(opt)\n",
    "    new_portfolio.save_as_quote()\n",
    "print(new_portfolio.id) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "swaption1 = IRSwaption(PayReceive.Pay, '5y', Currency.EUR, expiration_date='3m', name='EUR-3m5y')\n",
    "swaption2 = IRSwaption(PayReceive.Pay, '7y', Currency.EUR, expiration_date='6m', name='EUR-6m7y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "portfolio = Portfolio((swaption1, swaption2))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
